﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DesignPattern
{
    public  class RoadFactory : FacilitiesFactory
    {
        private static RoadFactory instance;
        private  RoadFactory()
        { }

        public static RoadFactory Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new RoadFactory();
                }
                return instance;
            }
        }

        public override Building CeateBuilding()
        {
            throw new NotImplementedException();
        }
        public override Jungle CreateJungle()
        {
            throw new NotImplementedException();
        }
        public override Road CreateRoad()
        {
            throw new NotImplementedException();
        }
        public override Tunnel CreateTunnel()
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// 道路
    /// </summary>
    public abstract class Road
    { }
    /// <summary>
    /// 建筑
    /// </summary>
    public abstract class Building
    { }
    /// <summary>
    /// 地道
    /// </summary>
    public abstract class Tunnel
    { }
    /// <summary>
    /// 丛林
    /// </summary>
    public abstract class Jungle
    { }

    public class ModernRoad : Road
    { }
    public class WaterRoad : Road
    { }

    public class ModernBuilding : Building
    { }
    public class BigBuilding : Building
    { }

    public class ModernTunnel : Tunnel
    { }
    public class ModernJungle : Jungle
    { }

    public abstract class FacilitiesFactory
    {
        public abstract Road CreateRoad();

        public abstract Building CeateBuilding();

        public abstract Tunnel CreateTunnel();

        public abstract Jungle CreateJungle();
    }

    public class ModernFacilitiesFactory : FacilitiesFactory
    {
        public override Road CreateRoad()
        {
            return new ModernRoad();
        }

        public override Building CeateBuilding()
        {
            return new ModernBuilding();
        }
        public override Jungle CreateJungle()
        {
            return new ModernJungle();
        }
        public override Tunnel CreateTunnel()
        {
            return new ModernTunnel();
        }
    }
    /// <summary>
    /// 客户程序
    /// </summary>
    class GameManager
    {
        FacilitiesFactory facilitiesFactory;
        public GameManager(FacilitiesFactory facilitiesFactory)
        {
            this.facilitiesFactory = facilitiesFactory;
        }

        Road road;
        Building building;
        Tunnel tunnel;
        Jungle jungle;
        public void BuildGameFacilities()
        {
            road = facilitiesFactory.CreateRoad();
            building = facilitiesFactory.CeateBuilding();
            tunnel = facilitiesFactory.CreateTunnel();
            jungle = facilitiesFactory.CreateJungle();
        }

        public void Run()
        {
            Console.WriteLine(road);
            Console.WriteLine(building);
            Console.WriteLine(tunnel);
            Console.WriteLine(jungle);
        }
    }

}
